<template>
    <div class="app-container">
        <div class="head">
            <img src="@/assets/img/Layout/position.png" />
            <p class="see-block">系统参数</p>
        </div>
        <div class="view-container">
            <el-form label-width="140px">
                <!-- <el-row class="mt30">
                    <el-col :span="8">
                        <el-button class="btn-success" type="primary">采购订单参数</el-button>
                    </el-col>
                </el-row>
                <el-row class="mt30">
                    <el-col :span="6">
                        <el-form-item label="允许审核:">
                            <el-select v-model="purchaseOrderCheck.ifAllow" style="width:100%;" placeholder="请选择" @change="(val) => onChangeSave(val, 'purchaseOrderCheck')">
                                <el-option label="是" value="0">是</el-option>
                                <el-option label="否" value="1">否</el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="允许反审核:">
                            <el-select v-model="purchaseOrderAntiAudit.ifAllow" style="width:100%;" placeholder="请选择" @change="(val) => onChangeSave(val, 'purchaseOrderAntiAudit')">
                                <el-option label="是" value="0">是</el-option>
                                <el-option label="否" value="1">否</el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row class="mt30">
                    <el-col :span="8">
                        <el-button class="btn-success" type="primary">销售订单参数</el-button>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="6" class="mt30">
                        <el-form-item label="允许审核:">
                            <el-select v-model="salesOrderCheck.ifAllow" style="width:100%;" placeholder="请选择" @change="(val) => onChangeSave(val, 'salesOrderCheck')">
                                <el-option label="是" value="0">是</el-option>
                                <el-option label="否" value="1">否</el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" class="mt30">
                        <el-form-item label="允许反审核:">
                            <el-select v-model="salesOrderAntiAudit.ifAllow" style="width:100%;" placeholder="请选择" @change="(val) => onChangeSave(val, 'salesOrderAntiAudit')">
                                <el-option label="是" value="0">是</el-option>
                                <el-option label="否" value="1">否</el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" class="mt30">
                        <el-form-item label="启用信用额度:">
                            <el-select v-model="salesOrderCredits.ifAllow" style="width:100%;" placeholder="请选择" @change="(val) => onChangeSave(val, 'salesOrderCredits')">
                                <el-option label="是" value="0">是</el-option>
                                <el-option label="否" value="1">否</el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" class="mt30">
                        <el-form-item label="超量销售:">
                            <el-select v-model="salesOrderOverSelling.ifAllow" style="width:100%;" placeholder="请选择" @change="(val) => onChangeSave(val, 'salesOrderOverSelling')">
                                <el-option label="是" value="0">是</el-option>
                                <el-option label="否" value="1">否</el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" class="mt30">
                        <el-form-item label="订单关联生成:">
                            <el-select v-model="salesOrderOrderAssociation.ifAllow" style="width:100%;" placeholder="请选择" @change="(val) => onChangeSave(val, 'salesOrderOrderAssociation')">
                                <el-option label="发货通知" value="0">发货通知</el-option>
                                <el-option label="销售出库" value="1">销售出库</el-option>
                                <el-option label="不关联生成" value="2">不关联生成</el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" class="mt30">
                        <el-form-item label="路由设置:">
                            <el-select v-model="salesOrderReleaseOrSales.ifAllow" style="width:100%;" placeholder="请选择" @change="(val) => onChangeSave(val, 'salesOrderReleaseOrSales')">
                                <el-option label="生成发货通知" value="0">生成发货通知</el-option>
                                <el-option label="生成销售出库" value="1">生成销售出库</el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row> -->
                <el-row class="mt30">
                    <el-col :span="8">
                        <el-button class="btn-success" type="primary">采购入库参数</el-button>
                    </el-col>
                </el-row>
                <el-row class="mt30">
                    <el-col :span="6">
                        <el-form-item label="允许拆单:">
                            <el-select v-model="purInboundSplitOrder.ifAllow" style="width:100%;" placeholder="请选择" @change="(val) => onChangeSave(val, 'purInboundSplitOrder')">
                                <el-option label="是" value="0">是</el-option>
                                <el-option label="否" value="1">否</el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="允许超量入库:">
                            <el-select v-model="purInboundOverStocking.ifAllow" style="width:100%;" placeholder="请选择" @change="(val) => onChangeSave(val, 'purInboundOverStocking')">
                                <el-option label="是" value="0">是</el-option>
                                <el-option label="否" value="1">否</el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="允许部分入库:">
                            <el-select v-model="purInboundPartStocking.ifAllow" style="width:100%;" placeholder="请选择" @change="(val) => onChangeSave(val, 'purInboundPartStocking')">
                                <el-option label="是" value="0">是</el-option>
                                <el-option label="否" value="1">否</el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="是否免审核:">
                            <el-select v-model="purInboundNoCheck.ifAllow" style="width:100%;" placeholder="请选择" @change="(val) => onChangeSave(val, 'purInboundNoCheck')">
                                <el-option label="是" value="0">是</el-option>
                                <el-option label="否" value="1">否</el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row class="mt30">
                    <el-col :span="8">
                        <el-button class="btn-success" type="primary">销售出库参数</el-button>
                    </el-col>
                </el-row>
                <el-row class="mt30">
                    <el-col :span="6">
                        <el-form-item label="允许拆单:">
                            <el-select v-model="outSaleSplitOrder.ifAllow" style="width:100%;" placeholder="请选择" @change="(val) => onChangeSave(val, 'outSaleSplitOrder')">
                                <el-option label="是" value="0">是</el-option>
                                <el-option label="否" value="1">否</el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <!-- <el-col :span="6">
                        <el-form-item label="允许超量出库:">
                            <el-select v-model="outSaleOverOut.ifAllow" style="width:100%;" placeholder="请选择" @change="(val) => onChangeSave(val, 'outSaleOverOut')">
                                <el-option label="是" value="0">是</el-option>
                                <el-option label="否" value="1">否</el-option>
                            </el-select>
                        </el-form-item>
                    </el-col> -->
                    <el-col :span="6">
                        <el-form-item label="允许部分出库:">
                            <el-select v-model="outSalePartOut.ifAllow" style="width:100%;" placeholder="请选择" @change="(val) => onChangeSave(val, 'outSalePartOut')">
                                <el-option label="是" value="0">是</el-option>
                                <el-option label="否" value="1">否</el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row class="mt30">
                    <el-col :span="8">
                        <el-button class="btn-success" type="primary">商城管理参数</el-button>
                    </el-col>
                </el-row>
                <el-row class="mt30">
                    <el-col :span="6">
                        <el-form-item label="是否生成采购订单:">
                            <el-select v-model="generatePurchaseOrder.ifAllow" style="width:100%;" placeholder="请选择" @change="(val) => onChangeSave(val, 'generatePurchaseOrder')">
                                <el-option label="是" value="0">是</el-option>
                                <el-option label="否" value="1">否</el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <!-- <el-row class="mt30">
                    <el-col :span="8">
                        <el-button class="btn-success" type="primary">金蝶对接参数</el-button>
                    </el-col>
                </el-row>
                <el-row class="mt30">
                    <el-col :span="6">
                        <el-form-item label="金蝶参数:">
                            <el-select v-model="jinDieOrder.ifAllow" style="width:100%;" placeholder="请选择" @change="(val) => onChangeSave(val, 'jinDieOrder')">
                                <el-option label="是" value="0">是</el-option>
                                <el-option label="否" value="1">否</el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row> -->
            </el-form>
        </div>
    </div>
</template>

<script>
import { editConfig, listConfig } from "@/api/system/setting/config/config"
export default {
    name: "config",
    data() {
        return {
            purchaseOrderCheck: {}, // 采购订单审核
            purchaseOrderAntiAudit: {}, // 采购订单反审核
            salesOrderCheck: {}, // 销售订单审核
            salesOrderAntiAudit: {}, // 销售订单反审核
            salesOrderCredits: {}, // 销售订单信用额度
            salesOrderOverSelling: {}, // 销售订单超量销售
            salesOrderOrderAssociation: {}, // 销售订单订单关联
            salesOrderReleaseOrSales: {}, // 销售订单路由设置
            purInboundSplitOrder: {}, // 采购入库拆单
            purInboundOverStocking: {}, // 采购入库超量入库
            purInboundPartStocking: {}, // 采购入库部分入库
            outSaleSplitOrder: {}, // 销售出库拆单
            outSaleOverOut: {}, // 销售出库超量出库
            outSalePartOut: {}, // 销售出库部分出库
            purInboundNoCheck: {}, // 采购入库免提交
            generatePurchaseOrder: {}, // 是否生成采购订单
            jinDieOrder: {} // 金蝶
        }
    },
    created() {
        this.getConfig()
    },
    methods: {
        // 获取参数详情
        getConfig(){
            listConfig().then(res => {
                this.purchaseOrderCheck = res.data.find(item => item.modelId == 1 && item.typeId == 1)
                this.purchaseOrderAntiAudit = res.data.find(item => item.modelId == 1 && item.typeId == 2)
                this.salesOrderCheck = res.data.find(item => item.modelId == 2 && item.typeId == 1)
                this.salesOrderAntiAudit = res.data.find(item => item.modelId == 2 && item.typeId == 2)
                this.salesOrderCredits = res.data.find(item => item.modelId == 2 && item.typeId == 3)
                this.salesOrderOverSelling = res.data.find(item => item.modelId == 2 && item.typeId == 4)
                this.salesOrderOrderAssociation = res.data.find(item => item.modelId == 2 && item.typeId == 5)
                this.salesOrderReleaseOrSales = res.data.find(item => item.modelId == 2 && item.typeId == 11)
                this.purInboundSplitOrder = res.data.find(item => item.modelId == 3 && item.typeId == 10)
                this.purInboundOverStocking = res.data.find(item => item.modelId == 3 && item.typeId == 6)
                this.purInboundPartStocking = res.data.find(item => item.modelId == 3 && item.typeId == 7)
                this.purInboundNoCheck = res.data.find(item => item.modelId == 3 && item.typeId == 12)
                this.outSaleSplitOrder = res.data.find(item => item.modelId == 4 && item.typeId == 10)
                this.outSaleOverOut = res.data.find(item => item.modelId == 4 && item.typeId == 8)
                this.outSalePartOut = res.data.find(item => item.modelId == 4 && item.typeId == 9)
                this.generatePurchaseOrder = res.data.find(item => item.modelId == 5 && item.typeId == 13)
                this.jinDieOrder = res.data.find(item => item.modelId == 5 && item.typeId == 13)
            }) 
        },
        onChangeSave(val, e){
            let obj = {}
            if(e == 'purchaseOrderCheck'){
                this.purchaseOrderCheck.ifAllow = val
                obj = this.purchaseOrderCheck        
            }else if(e == 'purchaseOrderAntiAudit'){
                this.purchaseOrderAntiAudit.ifAllow = val
                obj = this.purchaseOrderAntiAudit
            }else if(e == 'salesOrderCheck'){
                this.salesOrderCheck.ifAllow = val
                obj = this.salesOrderCheck
            }else if(e == 'salesOrderAntiAudit'){
                this.salesOrderAntiAudit.ifAllow = val
                obj = this.salesOrderAntiAudit
            }else if(e == 'salesOrderCredits'){
                this.salesOrderCredits.ifAllow = val
                obj = this.salesOrderCredits
            }else if(e == 'salesOrderOverSelling'){
                this.salesOrderOverSelling.ifAllow = val
                obj = this.salesOrderOverSelling
            }else if(e == 'salesOrderOrderAssociation'){
                this.salesOrderOrderAssociation.ifAllow = val
                obj = this.salesOrderOrderAssociation
            }else if(e == 'salesOrderReleaseOrSales'){
                this.salesOrderReleaseOrSales.ifAllow = val
                obj = this.salesOrderReleaseOrSales
            }else if(e == 'purInboundSplitOrder'){
                this.purInboundSplitOrder.ifAllow = val
                obj = this.purInboundSplitOrder
            }else if(e == 'purInboundOverStocking'){
                this.purInboundOverStocking.ifAllow = val
                obj = this.purInboundOverStocking
            }else if(e == 'purInboundPartStocking'){
                this.purInboundPartStocking.ifAllow = val
                obj = this.purInboundPartStocking
            }else if(e == 'purInboundNoCheck'){
                this.purInboundNoCheck.ifAllow = val
                obj = this.purInboundNoCheck
            }else if(e == 'outSaleSplitOrder'){
                this.outSaleSplitOrder.ifAllow = val
                obj = this.outSaleSplitOrder
            }else if(e == 'outSaleOverOut'){
                this.outSaleOverOut.ifAllow = val
                obj = this.outSaleOverOut
            }else if(e == 'outSalePartOut'){
                this.outSalePartOut.ifAllow = val
                obj = this.outSalePartOut
            }else if(e == 'generatePurchaseOrder'){
                this.generatePurchaseOrder.ifAllow = val
                obj = this.generatePurchaseOrder
            }else{
                this.jinDieOrder.ifAllow = val
                obj = this.jinDieOrder
            }
            let { modelName, modelValue, typeName, typeValue, ...result } = obj
            // console.log(result)
            editConfig(result).then(res => {
                if(res.code == 200){
                    this.$modal.msgSuccess("操作成功")
                    this.getConfig()
                }
            })
        }
    }
}
</script>

<style scoped>
::v-deep .el-form-item{
    margin-bottom: 0;
}
</style>